/*
 * @Description: 预归档到
 */
import emitter from '@/plugins/global-callback';
import globalData from '@/plugins/data';
import globalMethods from '@/plugins/methods';
import {useBaseInfoWithOut} from "@/store/modules/base-info";

const useBaseInfo = useBaseInfoWithOut();
/**
 * @description:
 * @param {Function} submitResolve 控制最外层的提交是否继续
 * @return {Promise}
 */
export default async function pigeonhole(submitResolve) {
    return new Promise((resolve, reject) => {
        const appName = '1';
        const url = `${globalData.ctxPath}/doc.do?method=docPigeonhole&appName=${appName}`;

        const dialog = globalMethods.dialog({
            title: this.$i18n('doc.tree.move.title'),
            url,
            centered: true,
            transParams: {
                parentWin: window,
            },
            bodyStyle: {
                padding: 0,
            },
            footer:null,
            onCancel: () => {
                //关闭弹窗
                dialog.close();
                //阻止程序继续
                reject();
                //如有提交操作，就直接反回结果
                submitResolve && submitResolve();
            },
            onConfirm: () => {
                const currentWindow = dialog.dialog().contentWindow;
                currentWindow.transParams = { parentWin: window };
                currentWindow.toMove();
            },
        });
        // 添加事件
        emitter.subscribeOne('pigeonholeAddItem', (item) => {
            if (!item.confirm){
                //关闭弹窗
                dialog.close();
                //阻止程序继续
                reject();
                //如有提交操作，就直接反回结果
                submitResolve && submitResolve();
                return;
            }
            //关闭弹窗
            dialog.close();
            //返回数据
            resolve(item);
            console.log('pigeonholeAddItem', item);
            useBaseInfo.pigeonholeId = item.value;
        });
    });
}

/**
 * @description: 弹出 暂存待办情况下，归档无效！ 提示
 * @param {*} submitResolve
 * @return {*}
 */
export async function pigeonholeHint(submitResolve) {
    return new Promise((resolve, reject) => {
        this.$confirm({
            title: this.$i18n('common.system.hint.label'),
            content: this.$i18n('collaboration.zcdb.archive.js'),
            closable: true,
            onCancel: () => {
                reject();
                submitResolve();
            },
            onOk: () => {
                resolve();
            },
        });
    });
}
